import Vue from 'vue'
import Vuex from 'vuex'
import Yi from './modules/yi'
import Er from './modules/er'
Vue.use(Vuex)

export default new Vuex.Store({
  strict: true,//开启严格模式
  state: {
    // 存放数据
    colt: 100,
    name: '伟超',
    list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  },
  getters: {
    //计算
    sum (state) {
      return state.list.reduce((item, sum) => item + sum, 0)
    }
  },
  mutations: {
    //更改state数据===同步
    add (state, obj) {
      // state.colt += 10
      state.colt += obj.n
    },
    add1 (state, n) {
      // state.colt += 10
      state.colt += n
    }
  },
  actions: {

    //异步
    add1 (q, n) {
      setTimeout(() => {
        console.log('我是异步啊');
        console.log(q);
        q.commit('add1', n)
      }, 1000)
    }
  },
  modules: {
    Yi,
    Er
  }
})
